Content Switcher
Content Switchers are horizontal groups of two or more buttons that allow users to switch between alternate views of related content. There is only one content section displayed at a time.
#Examples
Use a ContentSwitcher
as a content switcher. A ContentSwitcher
looks and functions similarly to a button group. The difference is that a ContentSwitcher
always has one option selected by default, and only one option can be selected at a time. Each option contains a required text label and an optional icon. The large variant has a required text description - as well as the required text label - and can use either an icon or an illustration.
A default option for a ContentSwitcher
should be determined by its use.
Unselected options:
selectable options for each view or item.Selected option:
Only one option can be selected at a time and one should always be selected in a defaultContentSwitcher
. If you do not want to display any of the options selected, use the Nothing selected variant.Text label:
the text label should clearly describe the content that appears below theContentSwitcher
.
#Default
const options: ContentSwitcherOption[] = [
{ id: 1, label: "Option 1" },
{ id: 2, label: "Option 2" },
{ id: 3, label: "Option 3" },
];
const [state, setState] = useState(options[0]);
return <ContentSwitcher options={options} value={state} onChange={(item) => setState(item)} />;
#With Icons
const options: ContentSwitcherOption[] = [
{
id: 1,
label: "Option 1",
icon: (
<Icon>
<IconSettings />
</Icon>
),
},
{
id: 2,
label: "Option 2",
icon: (
<Icon>
<IconEdit />
</Icon>
),
},
{
id: 3,
label: "Option 3",
icon: (
<Icon>
<IconShare />
</Icon>
),
},
];
const [state, setState] = useState(options[0]);
return <ContentSwitcher options={options} value={state} onChange={(item) => setState(item)} />;
#Large Variant
Each option in the large variant contains a required text label, a required text description, and an optional icon or illustration.
const options: LargeContentSwitcherOption[] = [
{
id: 1,
label: "Option 1",
description: "Lorem ipsum dolor sit amet consectetur adipisicing elit.",
},
{
id: 2,
label: "Option 2",
icon: (
<Icon>
<IconEdit />
</Icon>
),
description:
"Lorem ipsum dolor sit amet consectetur adipisicing elit. Eos fuga totam numquam obcaecati rerum placeat voluptatibus nostrum ea ipsum.",
},
{
id: 3,
label: "Option 3",
icon: (
<Illustration
src={IllustrationEducate}
size={{ width: 32, height: 32 }}
alt="Illustration with custom size"
/>
),
description:
"Lorem ipsum dolor sit amet consectetur adipisicing elit. Eos fuga totam numquam obcaecati rerum placeat voluptatibus nostrum ea ipsum, officia nesciunt natus animi, eveniet assumenda earum. Fugiat velit eaque quae.",
},
];
const [state, setState] = useState(options[0]);
return (
<ContentSwitcher
options={options}
variant="large"
value={state}
onChange={(item) => setState(item)}
/>
);
#Nothing selected
Select none of the options by explicitly giving null
as value (not just undefined
).
const options: ContentSwitcherOption[] = [
{ id: 1, label: "Option 1" },
{ id: 2, label: "Option 2" },
{ id: 3, label: "Option 3" },
];
const [state, setState] = useState<ContentSwitcherOption | null>(null);
return <ContentSwitcher options={options} value={state} onChange={(item) => setState(item)} />;
#Properties
Property | Description | Defined | Value |
---|---|---|---|
valueRequired | | unknown Value of the form control | ||
onChangeRequired | | function Callback for onChange event | ||
optionsRequired | | object[] Array of optional values for the group | ||
nameOptional | string Name applied to the form control | ||
idOptional | string Id applied to the form control | ||
invalidOptional | boolean Is the form control invalid | ||
onBlurOptional | function Callback for onBlur event | ||
aria-labelOptional | string Label of the form control | ||
aria-describedbyOptional | string ID of an an element that describes what the form control is for | ||
aria-labelledbyOptional | string ID of an an element that labels this form control | ||
onInitOptional | function Execute once content switcher has been initialized | ||
inStaticModeOptional | "disable" | "hide" | "show" Specifies how content switcher looks in the static mode. Defaults to `disable`. | ||
data-observe-keyOptional | string Unique string, used by external script e.g. for event tracking | ||
classNameOptional | string Custom className that's applied to the outermost element (only intended for special cases) | ||
styleOptional | object Style object to apply custom inline styles (only intended for special cases) | ||
tabIndexOptional | number Tab index of the outermost HTML element of the component | ||
onKeyDownOptional | function Callback for onKeyDown event | ||
onMouseDownOptional | function Callback for onMouseDown event | ||
onMouseEnterOptional | function Callback for onMouseEnter event | ||
onMouseLeaveOptional | function Callback for onMouseLeave event | ||
onFocusOptional | function Callback for onFocus event | ||
variantOptional | "default" | "large" Variant |
#Guidelines
#Best practices
#Do not use when
#Accessibility
Explore detailed guidelines for this component: Accessibility Specifications